import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */


export const constantRoutes = [{
        path: '/login',
        component: () =>
            import ('@/views/login/index'),
        hidden: true
    },

    {
        path: '/404',
        component: () =>
            import ('@/views/404'),
        hidden: true
    },

    {
        path: '/',
        component: Layout,
        redirect: '/dashboard', // 重定向
        children: [{
            path: 'dashboard',
            name: 'Dashboard',
            component: () =>
                import ('@/views/dashboard/index'),
            meta: { title: '首页', icon: '首页' }
        }]
    },

    {
        path: '/dynamic',
        component: Layout,
        children: [{
            path: 'index',
            name: 'Dynamic',
            component: () =>
                import ('@/views/dynamic/index'),
            meta: { title: '疫情动态', icon: '动态' }
        }]
    },



    {
        path: '/map',
        component: Layout,
        redirect: '/map/index',
        name: 'Map',
        meta: { title: '疫情图表', icon: '数据统计' },
        children: [{
                path: 'index',
                name: 'ChinaMap',
                component: () =>
                    import ('@/views/map/index'),
                meta: { title: '中国疫情', icon: '中国' }
            },
            {
                path: 'worldMap',
                name: 'WorldMap',
                component: () =>
                    import ('@/views/map/worldMap'),
                meta: { title: '国外疫情', icon: '全球' }
            },
            {
                path: 'pie',
                name: 'Pie',
                component: () =>
                    import ('@/views/piechart/index'),
                meta: { title: '疫情饼状图', icon: '饼图' }
            },
            {
                path: 'forepie',
                name: 'Forepie',
                component: () =>
                    import ('@/views/forepie/index'),
                hidden: true
            }
        ]
    },
    {
        path: '/echarts',
        component: Layout,
        redirect: '/echarts/index',
        name: 'Echarts',
        meta: { title: '实时疫情', icon: '实时监测' },
        children: [{
                path: 'index',
                name: 'Echarts',
                component: () =>
                    import ('@/views/echarts/index'),
                meta: { title: '疫情趋势', icon: '趋势' }
            },
            {
                path: 'dataControl',
                name: 'DataControl',
                component: () =>
                    import ('@/views/DataControl/control'),
                meta: { title: '疫情总览', icon: '监控总览' }
            },
            {
                path: 'new',
                name: 'New',
                component: () =>
                    import ('@/views/newGet/index'),
                //隐藏左侧侧边栏
                hidden: true
            },
            {
                path: 'from',
                name: 'From',
                component: () =>
                    import ('@/views/Fromfoe/index'),
                //隐藏左侧侧边栏
                hidden: true
            },
            {
                path: 'from2',
                name: 'From2',
                component: () =>
                    import ('@/views/Fromfoe2/index'),
                //隐藏左侧侧边栏
                hidden: true
            },
            {
                path: 'from3',
                name: 'From3',
                component: () =>
                    import ('@/views/Fromfoe3/index'),
                //隐藏左侧侧边栏
                hidden: true
            },
            {
                path: 'new2',
                name: 'New2',
                component: () =>
                    import ('@/views/newGet2/index'),
                //隐藏左侧侧边栏
                hidden: true
            }
        ]
    },

    {
        path: '/hos',
        component: Layout,
        children: [{
                path: 'index',
                name: 'Hos',
                component: () =>
                    import ('@/views/hos/index'),
                meta: { title: '定点医院', icon: '医院' }

            },
            {
                path: 'detail',
                name: 'Detail',
                component: () =>
                    import ('@/views/location/index'),
                //隐藏左侧侧边栏
                hidden: true
            }
        ]
    },

    {
        path: '/manager',
        component: Layout,
        redirect: '/manager/article',
        name: 'Manager',
        meta: { title: '疫情管理', icon: '管理' },
        children: [{
                path: 'article',
                name: 'Article',
                component: () =>
                    import ('@/views/manager/article'),
                meta: { title: '新闻资讯', icon: '新闻' }
            },
            {
                path: 'category', //对应网页地址
                name: 'Category',
                component: () =>
                    import ('@/views/manager/category'),
                meta: { title: '咨询分类', icon: '分类' }
            },
            {
                path: 'hospital', //对应网页地址
                name: 'Hospital',
                component: () =>
                    import ('@/views/manager/hospital'),
                meta: { title: '定点医院', icon: '医院' }
            }
        ]
    },
    {
        path: '/configuration',
        component: Layout,
        redirect: '/configuration/usermanagement',
        name: 'Configuration',
        meta: { title: '基础配置', icon: '基础配置' },
        children: [{
                path: 'usermanagement',
                name: 'Usermanagement',
                component: () =>
                    import ('@/views/configuration/usermanagement'),

                meta: { title: '用户管理', icon: '用户管理' }
            },

            {
                path: 'rolemanagement', //对应网页地址
                name: 'Rolemanagement',
                component: () =>
                    import ('@/views/configuration/rolemanagement'),
                meta: { title: '角色管理', icon: '角色管理' }
            },

        ]
    },
    {
        path: '/data_List',
        component: Layout,
        redirect: '/data_List/table',
        name: 'Data_List',
        meta: { title: '疫情数据', icon: '数据' },
        children: [{
                path: 'table',
                name: 'Table',
                component: () =>
                    import ('@/views/dynamic_data/DataList'),
                meta: { title: '数据列表', icon: '列表' }
            },
            {
                path: 'updata', //对应网页地址
                name: 'Updata',
                component: () =>
                    import ('@/views/dynamic_data/DataUpdata'),
                meta: { title: '数据上报', icon: '上报' }
            }
        ]
    },
    {
        path: '/qhq',
        component: Layout,
        children: [{
            path: 'index',
            name: 'Qhq',
            component: () =>
                import ('@/views/qhq/index'),
            meta: { title: '全球疫情观测', icon: '世界' }
        }]
    },
    {
        path: '/guangxi',
        component: Layout,
        children: [{
            path: 'index',
            name: 'Guangxi',
            component: () =>
                import ('@/views/guangxi/index'),
            meta: { title: '广西疫情', icon: '广西自治区' }
        }]
    },


    // 404 page must be placed at the end !!!
    { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
    // mode: 'hash', // require service support
    scrollBehavior: () => ({ y: 0 }),
    // mode: 'hash',
    // mode: 'history',
    routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router